﻿namespace Blaze.Editor.BehaviourTree.Inspectors
{
//    using BehaviorDesigner.Runtime;
    using System;
    using System.Collections.Generic;
    using UnityEditor;
    using UnityEngine;

//    [CustomEditor(typeof(Behavior))]
    public class BehaviorInspector : Editor
    {
        private bool mShowOptions = true;
        private bool mShowVariables;
        private static int selectedVariableIndex = -1;
        private static string selectedVariableName;
        private static int selectedVariableTypeIndex;
        private static List<float> variablePosition;

//        public static bool DrawInspectorGUI(Behavior behavior, SerializedObject serializedObject, bool fromInspector, ref bool externalModification, ref bool showOptions, ref bool showVariables)
//        {
//            string str;
//            bool flag2;
//            EditorGUI.BeginChangeCheck();
//            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
//            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(120f) };
//            EditorGUILayout.LabelField("Behavior Name", options);
//            behavior.GetBehaviorSource().behaviorName = EditorGUILayout.TextField(behavior.GetBehaviorSource().behaviorName, new GUILayoutOption[0]);
//            if (fromInspector && GUILayout.Button("Open", new GUILayoutOption[0]))
//            {
//                DesignerWindow.ShowWindow();
//                DesignerWindow.instance.LoadBehavior(behavior.GetBehaviorSource(), false, true);
//            }
//            GUILayout.EndHorizontal();
//            EditorGUILayout.LabelField("Behavior Description", new GUILayoutOption[0]);
//            GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.Height(48f) };
//            behavior.GetBehaviorSource().behaviorDescription = EditorGUILayout.TextArea(behavior.GetBehaviorSource().behaviorDescription, BehaviorDesignerUtility.TaskInspectorCommentGUIStyle, optionArray2);
//            serializedObject.Update();
//            GUI.enabled = (PrefabUtility.GetPrefabType(behavior) != PrefabType.PrefabInstance) || BehaviorDesignerPreferences.GetBool(BDPreferences.EditablePrefabInstances);
//            SerializedProperty property = serializedObject.FindProperty("externalBehavior");
//            ExternalBehavior objectReferenceValue = property.objectReferenceValue as ExternalBehavior;
//            EditorGUILayout.PropertyField(property, true, new GUILayoutOption[0]);
//            serializedObject.ApplyModifiedProperties();
//            if ((!object.ReferenceEquals(behavior.get_ExternalBehavior(), null) && !behavior.get_ExternalBehavior().Equals(objectReferenceValue)) || (!object.ReferenceEquals(objectReferenceValue, null) && !objectReferenceValue.Equals(behavior.get_ExternalBehavior())))
//            {
//                if (!object.ReferenceEquals(behavior.get_ExternalBehavior(), null))
//                {
//                    behavior.get_ExternalBehavior().get_BehaviorSource().set_Owner(behavior.get_ExternalBehavior());
//                    behavior.get_ExternalBehavior().get_BehaviorSource().CheckForSerialization(true, behavior.GetBehaviorSource());
//                }
//                else
//                {
//                    behavior.GetBehaviorSource().set_EntryTask(null);
//                    behavior.GetBehaviorSource().set_RootTask(null);
//                    behavior.GetBehaviorSource().set_DetachedTasks(null);
//                    behavior.GetBehaviorSource().set_Variables(null);
//                    behavior.GetBehaviorSource().CheckForSerialization(true, null);
//                    behavior.GetBehaviorSource().set_Variables(null);
//                    if (BehaviorDesignerPreferences.GetBool(BDPreferences.BinarySerialization))
//                    {
//                        BinarySerialization.Save(behavior.GetBehaviorSource());
//                    }
//                    else
//                    {
//                        JSONSerialization.Save(behavior.GetBehaviorSource());
//                    }
//                }
//                externalModification = true;
//            }
//            GUI.enabled = true;
//            EditorGUILayout.PropertyField(serializedObject.FindProperty("group"), true, new GUILayoutOption[0]);
//            if (fromInspector)
//            {
//                str = "BehaviorDesigner.VariablesFoldout." + behavior.GetHashCode();
//                showVariables = flag2 = EditorGUILayout.Foldout(EditorPrefs.GetBool(str, true), "Variables");
//                if (flag2)
//                {
//                    EditorGUI.indentLevel++;
//                    bool flag = false;
//                    BehaviorSource behaviorSource = behavior.GetBehaviorSource();
//                    List<SharedVariable> allVariables = behaviorSource.GetAllVariables();
//                    if ((allVariables != null) && (allVariables.Count > 0))
//                    {
//                        if (VariableInspector.DrawAllVariables(false, behaviorSource, ref allVariables, false, ref variablePosition, ref selectedVariableIndex, ref selectedVariableName, ref selectedVariableTypeIndex, false, true))
//                        {
//                            if (!EditorApplication.isPlayingOrWillChangePlaymode && (behavior.get_ExternalBehavior() != null))
//                            {
//                                BehaviorSource localBehaviorSource = behavior.get_ExternalBehavior().GetBehaviorSource();
//                                localBehaviorSource.CheckForSerialization(true, null);
//                                if (VariableInspector.SyncVariables(localBehaviorSource, allVariables))
//                                {
//                                    if (BehaviorDesignerPreferences.GetBool(BDPreferences.BinarySerialization))
//                                    {
//                                        BinarySerialization.Save(localBehaviorSource);
//                                    }
//                                    else
//                                    {
//                                        JSONSerialization.Save(localBehaviorSource);
//                                    }
//                                }
//                            }
//                            flag = true;
//                        }
//                    }
//                    else
//                    {
//                        EditorGUILayout.LabelField("There are no variables to display", new GUILayoutOption[0]);
//                    }
//                    if (flag)
//                    {
//                        if (BehaviorDesignerPreferences.GetBool(BDPreferences.BinarySerialization))
//                        {
//                            BinarySerialization.Save(behaviorSource);
//                        }
//                        else
//                        {
//                            JSONSerialization.Save(behaviorSource);
//                        }
//                    }
//                    EditorGUI.indentLevel--;
//                }
//                EditorPrefs.SetBool(str, showVariables);
//            }
//            str = "BehaviorDesigner.OptionsFoldout." + behavior.GetHashCode();
//            if (fromInspector)
//            {
//                showOptions = flag2 = EditorGUILayout.Foldout(EditorPrefs.GetBool(str, true), "Options");
//                if (!flag2)
//                {
//                    goto Label_044F;
//                }
//            }
//            if (fromInspector)
//            {
//                EditorGUI.indentLevel++;
//            }
//            EditorGUILayout.PropertyField(serializedObject.FindProperty("startWhenEnabled"), true, new GUILayoutOption[0]);
//            EditorGUILayout.PropertyField(serializedObject.FindProperty("pauseWhenDisabled"), true, new GUILayoutOption[0]);
//            EditorGUILayout.PropertyField(serializedObject.FindProperty("restartWhenComplete"), true, new GUILayoutOption[0]);
//            EditorGUILayout.PropertyField(serializedObject.FindProperty("resetValuesOnRestart"), true, new GUILayoutOption[0]);
//            EditorGUILayout.PropertyField(serializedObject.FindProperty("logTaskChanges"), true, new GUILayoutOption[0]);
//            if (fromInspector)
//            {
//                EditorGUI.indentLevel--;
//            }
//            Label_044F:
//            if (fromInspector)
//            {
//                EditorPrefs.SetBool(str, showOptions);
//            }
//            if (EditorGUI.EndChangeCheck())
//            {
//                serializedObject.ApplyModifiedProperties();
//                return true;
//            }
//            return false;
//        }

        private void OnEnable()
        {
//            Behavior target = this.target as Behavior;
//            if (target != null)
//            {
//                GizmoManager.UpdateGizmo(target);
//            }
        }

        public override void OnInspectorGUI()
        {
//            Behavior target = this.target as Behavior;
//            if (target != null)
//            {
//                bool externalModification = false;
//                if (DrawInspectorGUI(target, base.serializedObject, true, ref externalModification, ref this.mShowOptions, ref this.mShowVariables))
//                {
//                    BehaviorDesignerUtility.SetObjectDirty(target);
//                    if ((externalModification && (BehaviorDesignerWindow.instance != null)) && (target.GetBehaviorSource().get_BehaviorID() == BehaviorDesignerWindow.instance.ActiveBehaviorID))
//                    {
//                        BehaviorDesignerWindow.instance.LoadBehavior(target.GetBehaviorSource(), false, false);
//                    }
//                }
//            }
        }
    }
}